package me.joshua.tools4j.service;

import org.apache.log4j.Logger;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMailMessage;
import org.springframework.scheduling.annotation.Async;

public class MailService extends JavaMailSenderImpl {

	private final static Logger	LOGGER	= Logger.getLogger(MailService.class);

	/**
	 * Encapsulate send method, make it asynchronous and catch errors.
	 */
	@Async
	public void send(SimpleMailMessage mail) {
		try {
			super.send(mail);
		} catch (Exception e) {
			LOGGER.error("Send mail error", e);
		}
	}
	
	@Async
	public void send(MimeMailMessage mail) {
		try {
			super.send(mail.getMimeMessage());
		} catch (Exception e) {
			LOGGER.error("Send mail error", e);
		}
	}
}
